package solution;


/**
 * create by yongli on 2020-07-22 12:01
 */

public class FormatNumber {

    public static void main(String[] args) {
        // 116, 111，121
        //  1166 , 1111,1221

        System.out.println((1111 + 1221) / 2);

    }

    // 输出离a最近的对称数
    // a=1,2,3
    public static void duicheng(int a) {
        // 它本身
        if (a < 10) {
            System.out.print(a);
        }

        // 123 -> 99  121,323,最近的数,高位变动少
        // 102 -> 99,101
        // 123456

        else {
            String str = String.valueOf(a);
            int[] arr = new int[str.length()];

            int len = arr.length;
            for (int i = 0; i < len; i++) {
                arr[i] = str.charAt(i) - 48;
            }
            int i = 0;
            for (; i < len / 2; i++) {
                // 检测
                if (arr[i] != arr[len - i - 1]) {
                    break;
                }
            }
            // 本身对称
            if (i == len / 2) {
                System.out.println(a);
            } else {

                // 中间数不变
                for (int j = 0; j < len / 2; j++) {
                    // 最近的数
                    arr[len - i - 1] = arr[i];
                }
                StringBuilder sb = new StringBuilder();
                for (int n : arr) {
                    sb.append(n);

                }
                int res1 = Integer.valueOf(new String(sb));

                // 中间数变+
                int res3 = -1;
                for (int j = 0; j < len / 2 - 1; j++) {
                    // 最近的数
                    arr[len - i - 1] = arr[i];
                }
                int m = arr[len / 2 - 1] + 1;
                if (m < 10) {
                    arr[len / 2 - 1] = m;
                    arr[len / 2] = m;
                    StringBuilder sb3 = new StringBuilder();
                    for (int n : arr) {
                        sb3.append(n);
                    }
                    res3 = Integer.valueOf(new String(sb3));
                }


                StringBuilder sb2 = new StringBuilder();
                for (int k = 0; k < len - 1; k++) {
                    sb2.append(9);
                }
                int res2 = Integer.valueOf(new String(sb2));
                if (res1 - a == a - res2) {
                    System.out.println(res2 + "，" + res1);
                } else if (res3 != -1 && res3 - a == a - res1) {
                    System.out.println(res1 + "," + res3);
                } else {
                    System.out.println(res1);
                }
            }
        }

    }

}
